var pro =  [{
  g: '../img/car/0.png',
  pic: '../img/car/1.png',
  des: '三的 SD-JR02绞肉机家用电动小型搅馅切菜打碎...',
  detail: '颜色：绿色  规格...',
  price: 69
}, {
  g: '../img/car/0.png',
  pic: '../img/car/2.png',
  des: '三的 SD-JR09D绞肉机压力锅全能烹饪智能安全锁...',
  detail: '颜色：银色  规格...',
  price: 99
}]
var total = 0
var g = '../img/car/0.png'
Page({
  data: {
    a:'',
    g: g,
    ppzy:'../img/car/ppzy.png',
    pro:pro,
    total:total
  },
  onLoad: function (options) {

  },
  jiesuan(){
   wx.showModal({
     title: '确认下单？',
     content: '确认',
     success:function(res){
        if(res.confirm){
          wx.showToast({
            title: '付款成功',
            duration:5000
          })
          wx.navigateTo({
            url: '../index/index',
          })
        }
     }
   })
  },
  swithG(e){
    var id = e.currentTarget.id
      if (pro[id].g == '../img/car/0.png') {
        pro[id].g = '../img/car/g.png'
        total += pro[id].price
      }
      else {
        pro[id].g = '../img/car/0.png'
        total -= pro[id].price
      }
      if (pro[0].g == '../img/car/g.png' && pro[1].g == '../img/car/g.png') {
        g = '../img/car/g.png'
        this.setData({ g: g, a: '(2)' })
      } else if (pro[0].g != '../img/car/g.png' && pro[1].g != '../img/car/g.png') {
        this.setData({ a: '' })
      } else {
        this.setData({ a: '(1)' })
      }
      this.setData({ pro: pro, total: total })
    },
    switchHH(){
      if (g == '../img/car/g.png'){
        g = '../img/car/0.png'
        pro[0].g = g
        pro[1].g = g
        this.setData({ g: g, a: '' ,pro:pro,total:0})
      }
     else{
        g = '../img/car/g.png'
        pro[0].g = g
        pro[1].g = g
        this.setData({ g: g, a: '(2)', pro: pro ,total:168})
     }
    }
})